@extends('admin.common.app')
@section('css')
    <link rel="stylesheet" href="/admin/css/pagination.css">
    @endsection
@section('cont')

    <section class="Hui-article-box">
        <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页
            <span class="c-gray en">&gt;</span>
            管理员管理
            <span class="c-gray en">&gt;</span>
            管理员列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" >
                <i class="Hui-iconfont">&#xe68f;</i>
            </a>
        </nav>
        <div class="Hui-article">
            <article class="cl pd-20">
                <div class="text-c"> 日期范围：
                    <input type="text" onfocus="WdatePicker({maxDate:'#F{$dp.$D(\'datemax\')||\'%y-%M-%d\'}'})" id="datemin" class="input-text Wdate" style="width:120px;">
                    -
                    <input type="text" onfocus="WdatePicker({minDate:'#F{$dp.$D(\'datemin\')}',maxDate:'%y-%M-%d'})" id="datemax" class="input-text Wdate" style="width:120px;">
                    <input type="text" class="input-text" style="width:250px" placeholder="输入管理员名称" id="" name="">
                    <button type="submit" class="btn btn-success" id="" name=""><i class="Hui-iconfont">&#xe665;</i> 搜管理员</button>
                </div>
                <div class="cl pd-5 bg-1 bk-gray mt-20">
                    <span class="l">
                        <a href="{{route('admin.student.create')}}"  class="btn btn-primary radius">
                            <i class="Hui-iconfont">&#xe600;</i>
                            添加学生账号</a>
                         <a href="{{route('admin.student.batch')}}"  class="btn btn-primary radius">
                            <i class="Hui-iconfont">&#xe604;</i>
                            批量生成学生账号</a>
                         <a href="{{route('admin.student.info')}}"  class="btn btn-primary radius">
                            <i class="Hui-iconfont">&#xe644;</i>
                            导出学生信息</a>
                    </span>
                </div>
                @include('admin.common.msg')
                <table class="table table-border table-bordered table-bg">
                    <thead>
                    <tr>
                        <th scope="col" colspan="9">学生列表</th>
                    </tr>
                    <tr class="text-c">
                        <th width="20">ID</th>
                        <th width="50">学号</th>
                        <th width="50">姓名</th>
                        <th width="20">性别</th>
                        <th width="80">班级</th>
                        <th width="100">手机号</th>
                        <th width="100">邮箱</th>
                        <th width="20">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    @foreach($data as $item)
                        <tr class="text-c">
                            <td>{{$item->id}}</td>
                            <td>{{$item->student_code}}</td>
                            <td>{{$item->name}}</td>
                            <td>
                                @if($item['sex']=='未知')
                                    <span class="label label-danger radius"> {{$item->sex}}</span>
                                @elseif($item['sex']=='女生')
                                    <span class="label label-success radius"> {{$item->sex}}</span>
                                @else
                                    <span class="label label-secondary radius"> {{$item->sex}}</span>
                                @endif
                            </td>
                            <td>{{$item->class_name}}</td>
                            <td>{{$item->phone}}</td>
                            <td>{{$item->email}}</td>
                            <td class="td-manage text-l">
                                <a href="{{route('admin.student.edit',$item)}}" class="label label-success radius">修改</a>
                                <a href="{{route('admin.student.destroy',$item)}}" class="label label-danger delbat radius">删除</a>
                            </td>
                        </tr>
                    @endforeach
                    </tbody>
                </table>
                {{$data->links()}}
            </article>
        </div>
    </section>
@endsection
@section('js')
    <script type="application/javascript">
        $('.delbat').click(function () {
            let url=$(this).attr('href');
            let _token="{{csrf_token()}}";
              const e=$(this).parents('tr');//父级 tr
                layer.confirm('真的删除行么', function(index){
                    layer.close(index);
                        $.ajax({
                            url,
                            type:'DELETE',
                            data:{_token},
                        }).then(({status,msg})=>{
                            if (status == 0){
                                layer.msg(msg, {
                                    icon: 2,
                                    time:2000,
                                    skin: 'layui-layer-molv' //样式类名
                                }, e.remove()//删除父级
                                 )
                            }
                        });
                    //向服务端发送删除指令
                });
            //取消默认事件
            return false;
        });
    </script>
@endsection
